package io.renren.modules.skate.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.constant.Constant;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.skate.dao.FClassifyDao;
import io.renren.modules.skate.dto.FClassifyDTO;
import io.renren.modules.skate.entity.FCertificateEntity;
import io.renren.modules.skate.entity.FClassifyEntity;
import io.renren.modules.skate.entity.FClubEntity;
import io.renren.modules.skate.service.FClassifyService;
import io.renren.modules.security.user.SecurityUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 分类表
 *
 * @author Mark sunlightcs@gmail.com
 * @since 3.0 2023-11-28
 */
@Service
public class FClassifyServiceImpl extends CrudServiceImpl<FClassifyDao, FClassifyEntity, FClassifyDTO> implements FClassifyService {

    @Override
    public QueryWrapper<FClassifyEntity> getWrapper(Map<String, Object> params){
        QueryWrapper<FClassifyEntity> wrapper = new QueryWrapper<>();

        String type = (String)params.get("type");
        if(StringUtils.isNotEmpty(type)){
            wrapper.eq("type",Integer.parseInt(type));
        }

        return wrapper;
    }


    @Override
    public FClassifyDTO queryByName(String classifyName) {
        FClassifyEntity fClassifyEntity = baseDao.selectOne(new QueryWrapper<FClassifyEntity>().eq("classify_name", classifyName).last("limit 1"));

        return ConvertUtils.sourceToTarget(fClassifyEntity, currentDtoClass());
    }

    // *********************************
    @Override
    public List<FClassifyDTO> queryByType(Integer type) {

        List<FClassifyEntity> list = baseDao.selectList(new QueryWrapper<FClassifyEntity>().eq("type", type));

        return ConvertUtils.sourceToTarget(list, currentDtoClass());
    }

    @Override
    public FClassifyDTO queryByTypeAndId(Integer id, Integer type) {

        FClassifyEntity fClassifyEntity = baseDao.selectOne(new QueryWrapper<FClassifyEntity>().eq("id", id).eq("type", type));

        return ConvertUtils.sourceToTarget(fClassifyEntity, currentDtoClass());
    }
}